<template>
  <base-breadcrumb>
    <searchData
      :searchData="searchArr"
      @search="search"
    ></searchData>
    <a-card>
      <div class="table-operator">
        <a-button
          v-btnPermission="'ds_015_add_01'"
          type="primary"
          icon="plus"
          @click="handleUpdate('add', {})"
        >新增会议</a-button>
      </div>
      <list-table
        ref="table"
        size="default"
        rowKey="key"
        :columns="columns"
        :request="loadData"
        :alert="true"
        show-size-changer
        show-quick-jumper
        showPagination="auto"
      >
        <span
          slot="operation"
          slot-scope="text, record"
        >
          <a
            @click="handleUpdate('start', record)"
            v-if="record.status == 20"
            v-btnPermission="'ds_015_edi_02'"
          >查看会议</a>
          <a
            @click="handleUpdate('edit', record)"
            v-if="record.status == 30"
            v-btnPermission="'ds_015_edi_02'"
          >进入会议</a>
          <a
            @click="handleUpdate('look', record)"
            v-if="record.status == 40"
            v-btnPermission="'ds_015_loo_03'"
          >查看会议</a>
        </span>
        <span
          slot="commentedPlan"
          slot-scope="text, record"
        >
          {{ record.meetingExtraVO.commentedPlan }}
        </span>
        <span
          slot="professionComName"
          slot-scope="text, record"
        >
          {{ record.meetingExtraVO.professionComName }}
        </span>
        <span
          slot="avgScore"
          slot-scope="text, record"
        >
          {{ record.meetingExtraVO.avgScore }}
        </span>

        <span
          slot="status"
          slot-scope="text, record"
        >
          <list-status
            :status="record.status"
            conversion="en"
            :text="text"
          ></list-status>
        </span>
      </list-table>
    </a-card>
  </base-breadcrumb>
</template>
<script>
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
import SelectSubcontractor from '@/components/Select/SelectSubcontractor' // 分包商
import { STable } from '@/components'
import listStatus from '@/components/list_status/meeting_status'
import { getMeetingList, startMeeting, getSearchList } from '@/api/office/conference'

const columns = [
  {
    title: '会议名称',
    dataIndex: 'meetingName'
  },
  {
    title: '会议类型',
    dataIndex: 'meetingTypeName'
  },
  {
    title: '所属分公司',
    dataIndex: 'branchComName'
  },
  {
    title: '所属项目',
    dataIndex: 'projectName'
  },
  {
    title: '召开时间',
    dataIndex: 'startTime'
  },
  {
    title: '参会人数',
    dataIndex: 'meetingCount'
  },
  // {
  //     title: '状态',
  //     dataIndex: 'status',
  //     scopedSlots: { customRender: 'status' },
  // },
  {
    title: '操作',
    dataIndex: 'operation',
    width: '170px',
    scopedSlots: { customRender: 'operation' }
  }
]
const searchArr = [
    // {
    //     name: '所属分公司',
    //     valueKey: 'branchComId',
    //     type: SelectSubCompany,
    // },
    {
      name: '所属单位',
      valueKey: 'searchQuery',
      type: OrgTreeSelect,
    },
    // {
    //     name: '所属项目',
    //     keyValue: 'branchComId',
    //     valueKey: 'projectId',
    //     type: SelectProject,
    // },
    {
        name: '会议名称',
        value: 'meetingName',
        type: 'input',
    },
    {
        name: '召开时间',
        value: 'startEndDate',
        type: 'dateRange',
    },
    // {
    //     name: '状态',
    //     value: 'status',
    //     type: 'select',
    //     data: [
    //         {
    //             value: '20',
    //             label: '待开始',
    //         },
    //         {
    //             value: '30',
    //             label: '进行中',
    //         },
    //         {
    //             value: '35',
    //             label: '审批中',
    //         },
    //         {
    //             value: '40',
    //             label: '已完结',
    //         },
    //     ],
    // },
]
export default {
  name: 'a' + Date.now(),
  components: {
    STable,
    listStatus
  },
  data() {
    this.columns = columns
    this.searchArr = searchArr
    return {
      queryParam: {},
      loadData: async (parameter) => {
        this.queryParam.query = { ...this.queryParam.query, typeId: 9 }
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        const [err, res] = await getMeetingList(requestParameters)
        return new Promise((resolve, reject) => {
          if (err) {
            reject(err)
          } else {
            resolve(res)
          }
        })
      }
    }
  },
  mounted() {
    // this.getSearchListReq()
  },
  methods: {
    // async getSearchListReq() {
    //     const [err, res] = await getSearchList({ typeId: 9 })
    //     if (!err) {
    //         res.data.forEach((item) => {
    //             item.value = item.id
    //             item.label = item.name
    //         })
    //         searchArr[2].data = res.data || []

    //     }
    //      this.searchArr = searchArr
    // },
    //搜索
    search(val = {}) {
      this.queryParam.query = {
        ...val,
        typeId: 9,
        hsemonth: (val.month && val.month.format('YYYY-MM')) || void 0,
        startTime: (val.startEndDate && val.startEndDate.length && val.startEndDate[0].format('YYYY-MM-DD')) || void 0,
        endTime: (val.startEndDate && val.startEndDate.length && val.startEndDate[1].format('YYYY-MM-DD')) || void 0
      }
      console.log(this.queryParam)

      this.$refs.table.refresh(true)
    },

    // 处理更新操作（新增、编辑）
    async handleUpdate(type, data = {}) {
      if (type == 'del') {
        // const [err, res] = await deleteEquipment({ id: data.id })
        // if (!err) {
        //     this.$message.success('成功')
        //     this.$refs.table.refresh(true)
        // }
      }
      // else if (type == 'start') {
      //     const [err, res] = await startMeeting({ id: data.id })
      //     if (!err) {
      //         this.$message.success('成功')
      //         this.$refs.table.refresh(true)
      //     }
      // }
      else if (type == 'edit' || type == 'look' || type == 'start') {
        this.$router.push({
          name: 'designMeetingInputSummary',
          query: {
            id: data.id || '',
            pageType: type
          }
        })
      } else {
        this.$router.push({
          name: 'designMeetingAddConference',
          query: {
            id: data.id || '',
            pageType: type,
            typeId: 9
          }
        })
      }
    }
  }
}
</script>
